package Java2;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.util.logging.Level;
import java.util.logging.Logger;


public class Fileread {   
	
	
	private static void copyFileUsingStream(File source, File dest) throws IOException {
	    InputStream is = null;
	    OutputStream os = null;
	    try {
	        is = new FileInputStream(source);
	        os = new FileOutputStream(dest);
	        byte[] buffer = new byte[1024];
	        int length;
	        while ((length = is.read(buffer)) > 0) {
	            os.write(buffer, 0, length);
	        }
	    } finally {
	        is.close();
	        os.close();
	    }
	}

	public static void main(String args[]) throws IOException {


		FileInputStream fileread = new FileInputStream("histogram.txt");
		FileOutputStream filewrite = new FileOutputStream("histogrannew.txt");
		BufferedReader br = new BufferedReader(new InputStreamReader(fileread));
	

		String str;

		while((str = br.readLine()) != null)
		{
			System.out.println(str);


		}

		File source = new File("histogram.txt");
		File dest = new File("histogrannew.txt");
	
		long start = System.nanoTime();
		copyFileUsingStream(source, dest);


	}



}


